package ch.abcm.remsmobile;

import ch.abcm.remsmobile.multicastreceiver.REMSMulticastReceiver;
import ch.abcm.remsmobile.network.NetworkController;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import ch.abcm.remsmobile.REMSMobile.R;
import ch.bfh.abch.rems.REMSMulticastController;

public class REMSMainActivity extends Activity {

	private static final String TAG = "HelloAndroidActivity";
	private REMSMulticastController mcController;
	private static final int DEFAULT_TPORT = 9023;
	private static final String DEFAULT_MCADRESS = "224.0.0.251";

	/**
	 * Called when the activity is first created.
	 * 
	 * @param savedInstanceState
	 *            If the activity is being re-initialized after previously being
	 *            shut down then this Bundle contains the data it most recently
	 *            supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it
	 *            is null.</b>
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		this.mcController = new REMSMulticastController(DEFAULT_MCADRESS, DEFAULT_TPORT);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(ch.abcm.remsmobile.REMSMobile.R.menu.main, menu);
		return true;
	}

	public void onButtonClick(View view) {
		Log.d(TAG, "Button pressed: " + view.getId());
		switch (view.getId()) {
		case R.id.bu_main_repeat_status_update:
			sendBroadcast(new Intent(NetworkController.UPDATE_STATUS_ACTION));
			break;
		case R.id.bu_main_start_multicastreceiver:
			new REMSMulticastController().startMulticastReceiver(new REMSMulticastReceiver(this));
			break;
		}
	}

}
